import os
import string


LEARN_E_CMD_PATH = "./eCmd.txt"
session_file_path = "./uni_hb_m_solution/unione_lite_app_hb_m/src/app/src/sessions/uni_study_session.c"
# session_file_path = "./python/uni_study_session.c"
new_session_file_path = "./learnFile/uni_study_session.c"
learn_Voice_path = "./learnVoice"




#修改sdk里面
# const uni_u8 g_study_cmd_list[] = {
    #add learn seial
# };


# /** 学习命令词播报pcm列表
#  */
# const char *g_study_cmd_reply_pcm_list[] = {
    #add voice list
# };



print("start edit session study file")

sessionFd = open(session_file_path, mode="r", encoding='utf-8')
newSessionFd = open(new_session_file_path, mode="w", encoding='utf-8')
eCmdFd = open(LEARN_E_CMD_PATH, mode="r", encoding='utf-8')

num = 0
find_cmd_list = 0
find_pcm_list = 0

for line in sessionFd.readlines():

    if find_cmd_list == 0 and find_pcm_list == 0:
        newSessionFd.write(line)
    else:
        if line[0:len("};")] == "};":

            newSessionFd.write(line)

            if find_cmd_list == 1:
                find_cmd_list = 0

            if find_pcm_list == 1:
                find_pcm_list = 0

    if line[0:len("const uni_u8 g_study_cmd_list[] = {")] == "const uni_u8 g_study_cmd_list[] = {":
        print("find g_study_cmd_list", sessionFd.tell())

        find_cmd_list = 1
        for cmdLine in eCmdFd.readlines():
            print(cmdLine)
            num += 1
            newSessionFd.write('\t' + cmdLine)

    if line[0:len("const char *g_study_cmd_reply_pcm_list[] = {")] == "const char *g_study_cmd_reply_pcm_list[] = {":
        print("find g_study_cmd_reply_pcm_list")

        find_pcm_list = 1
        for i in range(num):
            voiceNum = 700+i
            newSessionFd.write('\t"' + str(voiceNum)+'",\n')


print("edit voice name to 7xx.mp3")

voice_list = os.listdir(learn_Voice_path)
for list in voice_list:
    if list[-3:] == 'mp3':
        print(list)
        os.rename(learn_Voice_path + '/' + list, learn_Voice_path + '/7' + list[1:])







